001 /**
002 * Created by IntelliJ IDEA.
003 * User: Wei Wang
004 * Date: Feb 26, 2003
005 * Time: 7:57:30 PM
006 */
007
008 package EVolve.util.painters.placements;
009
010 import EVolve.util.painters.shapes.Shape;
011 import EVolve.visualization.AutoImage;
012 import java.awt.*;
013
014 public class RoundPlacement extends Placement{
015
016 public RoundPlacement(int shapeSize) {
017 super();
018 this.shapeSize = shapeSize;
019 }
020
021 public String getName() {
022 return "Round Placement";
023 }
024
025 public Rectangle initialPlacement(AutoImage image) {
026 int totalShapes = parties[0].size() + parties[1].size();
027 int startX, startY;
028 double angle, radius, delta, x, y;
029
030 if (parties[0] == parties[1]) totalShapes /= 2;
031
032 radius = shapeSize/(Math.sin(Math.PI/totalShapes));
033 startX = startY = (int)radius+INDENT;
034 angle = 0;
035 delta = 2*Math.asin(shapeSize/radius);
036
037 int i = 0,producerSize = parties[0].size();
038 while (i<totalShapes) {
039 for (int j=0; j<parties[i/producerSize].size(); j++) {
040 Shape object = (Shape)parties[i/producerSize].get(new Integer(j));
041 x = startX + radius * Math.cos(angle);
042 y = startY + radius * Math.sin(angle);
043 object.move((int)x-shapeSize/2,(int)y-shapeSize/2);
044 angle += delta;
045 }
046 i += parties[i/producerSize].size();
047 }
048 Rectangle bounds = new Rectangle();
049 bounds.height = bounds.width = (int)(radius * 2 + shapeSize + INDENT*2);
050
051 image.setImageWidth(bounds.width, bounds.height);
052
053 return bounds;
054 }
055
056 }